# coding: utf-8
import shutil
from datetime import datetime
from enum import Enum
from pathlib import Path
from typing import Union, Any


def compress_folder_shutil(folder_path: Union[str, Path], output_path: Union[str, Path]):
    """
    压缩文件夹
    :param folder_path:
    :param output_path:
    :return:
    """
    shutil.make_archive(output_path, 'zip', folder_path)


def timestamp(length=13):
    time = datetime.now().timestamp()
    return str(int(time * 10 ** (int(length) - 10)))


def type_cast(value: Any) -> str:
    """
    类型转换
    :param value:
    :return:
    """
    if isinstance(value, Path):
        return str(value)
    elif isinstance(value, Enum):
        return value.value


def mkdir(*paths: Union[str, Path]):
    """
    创建目录
    :param paths:
    :return:
    """
    for path in paths:
        if not isinstance(path, Path):
            path = Path(path)
        path.mkdir(parents=True, exist_ok=True)


def touch(*paths: Union[str, Path]):
    """
    创建文件
    :param paths:
    :return:
    """
    for path in paths:
        if not isinstance(path, Path):
            path = Path(path)
        mkdir(path.absolute().parent)
        path.touch()
